import PyPDF2

# 打开PDF文件
with open('1.pdf', 'rb') as file:
    # 创建一个PDF阅读器对象
    reader = PyPDF2.PdfReader(file)
    # 获取PDF的页数
    num_pages = len(reader.pages)
    print(f"Number of pages: {num_pages}")

    # 读取每一页的内容
    res = []
    for page_num in range(num_pages):
        page = reader.pages[page_num]
        text = page.extract_text()
        contents = text.split("\n")
        for content in contents:
            res.append(content+"\n")

with open('1.txt','w',encoding='utf-8') as filetxt:
    filetxt.writelines(res)